<?php

namespace App\Http\Controllers;

use App\Models\Article;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class IndexController extends Controller
{
    public function index(Request $request)
    {
        $intro = Article::where('category_id', 1)->first();
        $product = Article::where('category_id', 2)->limit(5)->get();
        $about = Article::where('category_id', 3)->get();
        $big = Article::where('category_id', 4)->limit(3)->get();
        $en = $request->en ?? "en";
        return view("index", compact(['intro', 'product', 'about', 'en', 'big']));
    }


    public function sendMail(Request $request)
    {
        \App\Models\Mail::create(['company'=>$request->company,'name'=>$request->name,'email'=>$request->email,'phone'=>$request->phone,'country'=>$request->country,'message'=>$request->message]);

        Mail::raw("来自官网的邮件咨询：From Company($request->company)，请尽快回复邮件：".$request->email.",联系方式:".$request->phone."国家：".$request->country, function ($message)use($request) {
//            $to = $request->email;
            $to = 'jackxny@163.com';
            $message ->to($to)->subject($request->message);
        });

    }
}
